/*
* @Author: qingsong-Liu
* @Date:   2019-08-11 16:35:16
* @Last Modified by:   qingsong-Liu
* @Last Modified time: 2019-08-21 16:20:43
*/
'use strict';

var _mm = require('util/mm.js');

var _cart={
    // 获取购物车数量
    getCartCount:function(resolve,reject){
        _mm.request({
            url     : _mm.getServerUrl('/cart/get_cart_product_count.do'),
            success : resolve,
            error   : reject
        });
    },
    // 添加到购物车
    addToCart:function(productInfo,resolve,reject){
        _mm.request({
            url     : _mm.getServerUrl('/cart/add.do'),
            data    : productInfo,
            //todo 设为POST请求，方便接口测试,发布时要删除
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    // 获取购物车列表
    getCartList:function(resolve,reject){
        _mm.request({
            url     : _mm.getServerUrl('/cart/list.do'),
            success : resolve,
            error   : reject
        });
    },
    // 选中购物车商品
    selectProduct:function(productId,resolve,reject){
        _mm.request({
            url     : _mm.getServerUrl('/cart/select.do'),
            data    : {
                productId : productId
            },
            //todo 设为POST请求，方便接口测试,发布时要删除
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    // 取消选中购物车商品
    unselectProduct:function(productId,resolve,reject){
        _mm.request({
            url     : _mm.getServerUrl('/cart/un_select.do'),
            data    : {
                productId : productId
            },
            //todo 设为POST请求，方便接口测试,发布时要删除
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    // 选中全部商品
    selectAllProduct:function(resolve,reject){
        _mm.request({
            url     : _mm.getServerUrl('/cart/select_all.do'),
            success : resolve,
            error   : reject
        });
    },
    // 取消选中全部商品
    unselectAllProduct:function(resolve,reject){
        _mm.request({
            url     : _mm.getServerUrl('/cart/un_select_all.do'),
            success : resolve,
            error   : reject
        });
    },
    // 更新购物车商品数量
    updateProduct:function(productInfo,resolve,reject){
        _mm.request({
            url     : _mm.getServerUrl('/cart/update.do'),
            data    : productInfo,
            //todo 设为POST请求，方便接口测试,发布时要删除
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    // 移除指定商品
    deleteProduct:function(productIds,resolve,reject){
        _mm.request({
            url     : _mm.getServerUrl('/cart/delete_product.do'),
            data    : {
                productIds : productIds
            },
            //todo 设为POST请求，方便接口测试,发布时要删除
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    }
}
module.exports = _cart;